package it.stasbranger.myproject.client.managed.ui;

import com.google.gwt.core.client.GWT;

import com.google.gwt.dom.client.Element;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.HasClickHandlers;

import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;

import com.google.gwt.user.client.Window;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Widget;

import it.stasbranger.myproject.client.managed.request.SuppliersHasRequestsProxy;

import it.stasbranger.myproject.client.scaffold.place.ProxyDetailsView;

public class SuppliersHasRequestsMobileDetailsView extends Composite implements
		ProxyDetailsView<SuppliersHasRequestsProxy> {
	interface Binder extends
			UiBinder<HTMLPanel, SuppliersHasRequestsMobileDetailsView> {
	}

	private static final Binder BINDER = GWT.create(Binder.class);

	private static SuppliersHasRequestsMobileDetailsView instance;

	public static SuppliersHasRequestsMobileDetailsView instance() {
		if (instance == null) {
			instance = new SuppliersHasRequestsMobileDetailsView();
		}
		return instance;
	}

	SuppliersHasRequestsProxy proxy;

	@UiField
	Element suppliersIdsuppliers;
	@UiField
	Element requestsIdrequests;
	@UiField
	Element senddate;
	@UiField
	Element price;

	@UiField
	Element suppliers;
	@UiField
	Element requests;

	@UiField
	HasClickHandlers delete;

	private Delegate delegate;

	public SuppliersHasRequestsMobileDetailsView() {
		initWidget(BINDER.createAndBindUi(this));
	}

	public Widget asWidget() {
		return this;
	}

	public boolean confirm(String msg) {
		return Window.confirm(msg);
	}

	public SuppliersHasRequestsProxy getValue() {
		return proxy;
	}

	@UiHandler("delete")
	public void onDeleteClicked(ClickEvent e) {
		delegate.deleteClicked();
	}

	public void setDelegate(Delegate delegate) {
		this.delegate = delegate;
	}

	public void setValue(SuppliersHasRequestsProxy proxy) {
		this.proxy = proxy;

		suppliersIdsuppliers.setInnerText(String.valueOf(proxy.getSuppliersIdsuppliers()));
		requestsIdrequests.setInnerText(String.valueOf(proxy.getRequestsIdrequests()));
		senddate.setInnerText(String.valueOf(proxy.getSenddate()));
		price.setInnerText(String.valueOf(proxy.getPrice()));

		suppliers.setInnerText(it.stasbranger.myproject.client.managed.ui.SuppliersProxyRenderer.instance().render(proxy.getSuppliers()));

		requests.setInnerText(it.stasbranger.myproject.client.managed.ui.RequestsProxyRenderer.instance().render(proxy.getRequests()));
	}
}
